home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
BASIC
/
2620E.ZIP
/
PTOUCH.ZIP
/
FINDFILE.BAS
next >
Wrap
BASIC Source File
|
1990-04-08
|
5KB
|
137 lines
' SEE THE COMMENT BEFORE THE SAMPLE ABOUT COMPILING THIS
' Copr 1988, 1989 Barry Erick
$COMPILE UNIT
$LIB ALL OFF
$ERROR ALL OFF
DEFINT a-z
FUNCTION Findfirst$(filn$) public
'Copr 1988,1989 Barry Erick
LOCAL stringsegptr&,ferr%
LOCAL DTAAtt&,DTAOff&,DTASeg&,FExist$,Fil,Fil$,Ptr
' Format of the DTA after a file has been found:
'
' Offset Size(bytes) Description
' (D) (H)
' 0 0 21 15 Used by DOS for find next
' 21 15 1 1 Attribute of file found
' 22 16 2 2 Time Stamp of file
' 24 18 2 2 Date Stamp of file
' 26 1A 4 4 File size in bytes
' 30 1E 13 D Filename and extension (asciiz)
'
' Attributes:
' bit 0 - READ Only
' 1 - Hidden
' 2 - SYSTEM
' 3 - Volume Label
' 4 - Subdirectory
' 5 - Archive
' The formats for Time and Date are:
' Time = Hour * 2048 + Minute * 32 + Second / 2)
' Date = (Year - 1980) * 512 + Month * 32 + Day)
'
' see the file Exists.Bas for the routines to turn the time and date into
' their members
fexist$ = filn$+CHR$(0) ' make it a ASCIIZ string for DOS
REG 8,strseg(fexist$) ' String Segment to Reg DS
REG 4,strptr(Fexist$) ' String Seg Offset to Reg DX
REG 3,&H17 ' Find all but vol label Attribute
REG 1,&H4E00 ' DOS Function Find First Match
CALL INTERRUPT &H21 ' Just look for first matching file
ferr% = REG(1) ' Reg AX.. 0 = no error
IF ferr% = 2 OR_
ferr% = 18 OR_
ferr% = 3 OR_
ferr% = 15 THEN
Findfirst$ = ""
EXIT Function
END IF
' Get the dta that has the filename & stuff
REG 1,&H2F00 ' ah = 2F (Get DTA)
CALL INTERRUPT &h21 ' perform dos call
dtaseg& = REG(9) ' DTA segment = ES
dtaatt& = REG(2)+&H15 ' offset of attributes
dtaoff& = REG(2)+&H1E ' offset of filename
fil$ = "" ' prepare to retrieve filename
DEF SEG=dtaseg& ' set segment = DTA segment
FOR ptr% = 0 TO 12 ' retrieve filename
fil% = PEEK(dtaoff& + ptr%) ' from DTA
IF fil% = 0 THEN EXIT FOR
fil$ = fil$ + CHR$(PEEK(dtaoff& + ptr%))
NEXT ptr%
IF (PEEK(dtaatt&) AND 16) = 16 THEN
fil$ = "<"+fil$+">"' its a subdir ' look late to see if we really want it
END IF
DEF SEG ' reset segment to default
Findfirst$ = fil$
END Function
'[********************]
FUNCTION Findnext$ public
'Copr 1988,1989 Barry Erick
LOCAL fil$,dtaseg&,dtaoff&,dtaatt&,fil%,ptr%
REG 1,&h4F00
CALL INTERRUPT &h21
' return if errors and/or no files
IF REG(1) = 18 THEN
Findnext$ = ""
EXIT Function
END IF
REG 1,&H2F00
CALL INTERRUPT &H21
dtaseg& = REG(9) ' DTA segment = ES
dtaatt& = REG(2) + 21' offset of attributes
dtaoff& = REG(2) + 30' filename offset
fil$ = "" ' prepare to transfer filename
DEF SEG=dtaseg& ' set segment to DTA segment
FOR ptr% = 0 TO 12
fil% = PEEK(dtaoff& + ptr%) ' from DTA
IF fil% = 0 THEN EXIT FOR
fil$ = fil$ + CHR$(PEEK(dtaoff& + ptr%))
NEXT ptr%
IF (PEEK(dtaatt&) AND 16) = 16 THEN
fil$ = "<"+fil$+">"' mark subdirs, mask later if need be
END IF
DEF SEG ' restore default segment
Findnext$ = fil$
END FUNCTION
'[********************]
'**********************************************************************
' The following is a sample of how to use this *
' test findfile *
' This sample will not compile unless you change %NotComment to = -1 *
'**********************************************************************
%notcomment = 0
$IF %notcomment
INPUT "mask";mask$ 'mask can be wildcards
numfound% = 0
a$=Findfirst$(mask$)
IF a$="" THEN
PRINT mask$ ;"Not found"
END
ELSE
PRINT mask$;" found!"
INCR numfound%
PRINT USING "\ \";a$; 'print the first file
DO
a$=Findnext$
IF a$="" THEN EXIT LOOP
PRINT USING "\ \";a$;'print the rest
INCR numfound% 'note, you can save names
LOOP 'by sticking them in an
PRINT 'array, but for the demo, we
PRINT numfound%-1 ;"Files found" 'just print them
END IF
$ENDIF